package fr.inria.gforge.spoon.transformation.apichecking;

import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.MavenLauncher;
import spoon.compiler.Environment;
import spoon.reflect.factory.Factory;
import spoon.reflect.factory.FactoryImpl;
import spoon.support.DefaultCoreFactory;
import spoon.support.StandardEnvironment;

import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;

public class SpoonPomTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(SpoonPomTest.class);

    public Factory createFactory() {
        return new FactoryImpl(new DefaultCoreFactory(), createEnvironment());
    }

    public Environment createEnvironment() {
        return new StandardEnvironment();
    }

    @Test
    public void main() throws XmlPullParserException, IOException {
        String mvnHome = System.getenv().get("M2_HOME");
        System.out.println("M2_HOME=" + mvnHome);
        String mavenProject = ".";


        File mavenProjectFile = new File(mavenProject);
        Pattern profileFilter = Pattern.compile("^$");

        Factory factory = createFactory();
        SpoonPom model = new SpoonPom(mavenProject, MavenLauncher.SOURCE_TYPE.APP_SOURCE, factory.getEnvironment(), profileFilter);
        String[] classpath = model.buildClassPath(mvnHome, MavenLauncher.SOURCE_TYPE.APP_SOURCE, LOGGER, false);
        //MavenLauncher launcher = new MavenLauncher(projectPath, MavenLauncher.SOURCE_TYPE.APP_SOURCE);
        //MavenLauncher(String mavenProject, SOURCE_TYPE sourceType, String mvnHome, boolean forceRefresh) {
        //MavenLauncher launcher = new MavenLauncher(projectPath, MavenLauncher.SOURCE_TYPE.APP_SOURCE, "./mvnhome", false);

        // Environment environment = launcher.getEnvironment();
        // environment.setCommentEnabled(true);
        // environment.setAutoImports(true);

        //  launcher.addProcessor(new APICheckingProcessor());
        //  launcher.run();
    }
}
